import json
import os
from os.path import exists

Import("env")
json_build = 'build.json'
BUILD_NUMBER = 0
if os.path.exists(json_build):
    with open(json_build, 'r', encoding='utf-8') as f:
        build = json.load(f)
        BUILD_NUMBER = build['build']
print("BUILD_NUMBER=%s\n" % BUILD_NUMBER)
env.Append(BUILD_FLAGS=['-DBUILD_NUMBER=%s' % BUILD_NUMBER])
print(env['PIOPLATFORM'])
if env['PIOPLATFORM'] in ['sylixos_arm', 'sylixos_x86', 'sylixos_loong2k', 'sylixos_loongson']:
    json_build = 'build.json'
    if exists(json_build):
        with open(json_build, 'r', encoding='utf-8') as f:
            build = json.load(f)
            if build.get('Compiler'):
                env.Replace(_BINPREFIX=build['Compiler'])
